<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <#include "/common/plateform/include/common-base.ftl">
  <title>权限选择</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>

<!-- Part 一、 以下是body主体内容的模块区域 -->
<body>

		<section class="content">
			<div class="row">
				<div class="col-xs-12">
					<div class="box box-info box-solid">

						<div class="box-body">
							<table id="example" class="table tableEdit table-bordered table-hover" >
								<thead class="bg-success">
								<tr>
									<th>名称</th>
									<th>权限地址</th>
									<th class="text-center">选用</th>
								</tr>
								</thead>
								<tbody id="actList-body"></tbody>
							</table>
						</div>



					</div>
				</div>
			</div>
		</section>

		<script type="text/template" id="dataList">
			<? for ( var i = 0; i < rows.length; i++) {?>
			<tr id="<?=rows[i].uctAct.actId?>"  fatherId="<?=rows[i].uctAct.fatherId?>">
				<th style="display:none;"><?=rows[i].uctAct.actId?></th>
				<?if(rows[i].uctAct.subCount>0||"0"==rows[i].uctAct.fatherId){?>
					<td class="textLeft" id="css_<?=rows[i].uctAct.actId?>" onclick="getChildActsData('<?=rows[i].uctAct.fatherId?>','<?=rows[i].uctAct.actId?>','<?=rows[i].uctAct.fullEname?>',this);">
						<i class="fa fa-plus" ></i>&nbsp;<?=rows[i].uctAct.actCname?>
					</td>
				<?} else{?>
					<td class="textLeft" id="css_<?=rows[i].uctAct.actId?>">
						&nbsp;<?=rows[i].uctAct.actCname?>
					</td>
				<?}?>
				<td class="textLeft">
					<?=rows[i].uctAct.fullEname?>
				</td>
				<td class="text-center"><input type="checkbox" act-id="<?=rows[i].uctAct.actId?>" full-ename="<?=rows[i].uctAct.fullEname?>" onclick="getChecked(this)"/></td>

			</tr>
			<?}?>
		</script>
		<script>
            var clickMenu= 'user-act-list';
            var actId,orgEname,fatherId,actCname,fullEname,fullCname,isAdd=true;
            var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
            $(function () {
                getTableData();
                $('#example tbody').on('click','tr', function (e) {
                    if ( $(this).hasClass('selected') ) {
                        //$(this).removeClass('selected');
                    } else {
                        $('tr.selected').removeClass('selected');
                        $(this).addClass('selected');
                    }
                    actId = $('tr.selected th').eq(0).html();
                } );
            });

            //勾选对象
            function getChecked(obj){
                var actId = $(obj).attr("act-id");
                var fullEname = $(obj).attr("full-ename");
                $(obj).parent().addClass("bg-danger");
                if($(obj).is(':checked')){
                    var actObj = eval({"actId":actId,"fullEname":fullEname});
                    parent.preActObjCallBack(actObj);
                }else{
                    $(obj).parent().removeClass("bg-danger");
                }

            }

            function getTableData(){
                $("#actList-body").html("");
                var index_load = layer.load(1, {shade: false});
                $.ajax({type:'get',
                    url:common_list_url,
                    // data:{'id':'0','doCode':'treeAct'},
                    data:{'pageName':'uct-act-list','formName':'searchForm','uctAct.w_sysEname':defSysEname,'uctAct.w_fatherId':'0'},
                    dataType:'json',
                    success: function(myData){
                        console.log("myData",myData);
                        layer.close(index_load);
                        if(myData.total>0){
                            var data = baidu.template('dataList',eval(myData));
                            $("#actList-body").html(data);
						}
                    }
                });
            }


            function refresh(){
                actId="";
                getTableData();
            }

            function getChildActsData(fatherId,actId,treeLevel,obj){
                // alert(fatherId+"------"+actId+"------"+treeLevel+"------"+obj)
                var count =0;
                var ss = treeLevel.split("/");
                count = ss.length-1;
                $.ajax({ type:'get',url:common_list_url,
                    data:{'pageName':'uct-act-list','formName':'searchForm','uctAct.w_fatherId':actId,'orderBy':'uctAct.order_num'},
                    dataType:'json',
                    success: function(myData){
                        console.log(myData);
                        var data = baidu.template('dataList',myData);
                        if($(obj).find("i").hasClass("fa-minus")){
                            $(obj).find("i").attr("class","fa fa-plus"); delActsChiled(actId);
                        }else{
                            $(obj).find("i").attr("class","fa fa-minus");
                            $("#"+actId).after(data);
                            $("[fatherid='"+actId+"']").each(function(i){
                                var thisObj = $(this);
                                var pd = "10px 20px 10px ";
                                var num = pd+(count*20)+"px";
                                $(thisObj).find("td").eq(0).css("padding",num);
                            });
                        }
                    }
                });
            }
            function delActsChiled(id){
                $("[fatherid='"+id+"']").each(function(i){
                    var thisObj = $(this);
                    $(thisObj).remove();
                    var id = thisObj.attr("id");
                    delActsChiled(id);
                });
            }


		</script>


		<!-- Main end -->

<!-- /.content-wrapper -->
<!-- foot start -->
<!-- foot start -->
</body>
</html>

